package csdj.controller;

import com.lww.springcloudapi.pojo.TabHallSetmeal;
import com.lww.springcloudapi.result.LayuiEntity;
import com.lww.springcloudapi.result.Result;
import com.lww.springcloudapi.result.ResultCodeEnum;
import csdj.service.TabHallSetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hallSetMeal")
@Api(tags = "新增套餐信息")
//@CrossOrigin

public class TabHallSetmealController {
    @Autowired
    private TabHallSetmealService service;

    @ApiOperation(value = "新增套餐")
    @RequestMapping("/addSetMeal")
    @ResponseBody
    public LayuiEntity addSetMeal(TabHallSetmeal setmeal) {
        //1.创建返回对象
        LayuiEntity layuiEntity = new LayuiEntity();
        try {
            //2.包装返回对象
            Integer count = service.addSetMeal(setmeal);
            layuiEntity.setData(count);
            layuiEntity.setCode("200");
            layuiEntity.setMsg("新增成功");

        } catch (Exception e) {
            layuiEntity.setCode("500");
            layuiEntity.setMsg("新增失败");
        }
        return layuiEntity;
    }

    @ApiOperation(value = "删除套餐")
    @RequestMapping("/deleteSetMeal")
    @ResponseBody
    public LayuiEntity deleteSetMeal(Integer id) {
        //1.创建返回对象
        LayuiEntity layuiEntity = new LayuiEntity();
        try {
            //2.包装返回对象
            Integer count = service.deleteSetMeal(id);
            layuiEntity.setData(count);
            layuiEntity.setCode("200");
            layuiEntity.setMsg("删除成功");

        } catch (Exception e) {
            layuiEntity.setCode("500");
            layuiEntity.setMsg("删除失败");
        }

        return layuiEntity;
    }

    @ApiOperation(value = "修改套餐信息")
    @RequestMapping("/updateSetMeal")
    @ResponseBody
    public LayuiEntity updateSetMeal(TabHallSetmeal setmeal) {
        //1.创建返回对象
        LayuiEntity layuiEntity = new LayuiEntity();
        try {
            //2.包装返回对象
            Integer count = service.updateSetMeal(setmeal);
            layuiEntity.setData(count);
            layuiEntity.setCode("200");
            layuiEntity.setMsg("修改成功");

        } catch (Exception e) {
            layuiEntity.setCode("500");
            layuiEntity.setMsg("修改失败");
        }
        return layuiEntity;
    }

    @ApiOperation(value = "查看全部套餐")
    @RequestMapping("/selectSetMeal")
    @ResponseBody
    public LayuiEntity selectSetMeal() {
        //1.创建返回对象
        LayuiEntity layuiEntity = new LayuiEntity();
        try {
            //2.包装返回对象
            List<TabHallSetmeal> list = service.selectSeteal();
            layuiEntity.setData(list);
            layuiEntity.setCode("200");
            layuiEntity.setMsg("查询成功");

        } catch (Exception e) {
            layuiEntity.setCode("500");
            layuiEntity.setMsg("查询失败，请联系管理员");
        }
        return layuiEntity;
    }
}
